//
//  SAPWeatherTableViewCell.m
//  CarsHome
//
//  Created by dapeng on 15/12/12.
//  Copyright © 2015年 dapeng. All rights reserved.
//

#import "SAPWeatherTableViewCell.h"
#import "SAPYesterdayModel.h"
@implementation SAPWeatherTableViewCell
- (void)dealloc {
    [super dealloc];
}
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.tempe = [[UILabel alloc] init];
        self.tempe2 = [[UILabel alloc] init];
        self.weathers = [[UILabel alloc] init];
        self.time = [[UILabel alloc] init];
        self.city = [[UILabel alloc] init];
        self.date = [[UILabel alloc] init];
        self.hight = [[UILabel alloc] init];
        self.low = [[UILabel alloc] init];
        self.type = [[UILabel alloc] init];
        self.fl = [[UILabel alloc] init];
        self.fx = [[UILabel alloc] init];
        [_tempe2 release];
        [_city release];
        [_tempe release];
        [_time release];
        [_weathers release];
        [_date release];
        [_hight release];
        [_low release];
        [_type release];
        [_fl release];
        [_fx release];
        [self addSubview:self.tempe];
        [self addSubview:self.time];
        [self addSubview:self.city];
        [self addSubview:self.tempe2];
        [self addSubview:self.weathers];
        [self addSubview:self.date];
        [self addSubview:self.hight];
        [self addSubview:self.low];
        [self addSubview:self.type];
        [self addSubview:self.fl];
        [self addSubview:self.fx];
        [_weathers release];
        [_tempe2 release];
        [_city release];
        [_tempe release];
        [_time release];
        [_date release];
        [_hight release];
        [_low release];
        [_type release];
        [_fl release];
        [_fx release];
        for (int i = 0; i < 5; i++) {
            
            UILabel *hight = [[UILabel alloc] initWithFrame:CGRectZero];
            hight.textColor = [UIColor whiteColor];
            hight.font = [UIFont systemFontOfSize:12];
            hight.tag = i + 100;
            
            UILabel *low = [[UILabel alloc] initWithFrame:CGRectZero];
            low.font = [UIFont systemFontOfSize:12];
            low.textColor = [UIColor whiteColor];
            low.tag = i + 200;
            
            UILabel *type = [[UILabel alloc] initWithFrame:CGRectZero];
            type.tag = i + 300;
            type.textColor = [UIColor whiteColor];
            type.font = [UIFont systemFontOfSize:12];
            
            UILabel *fengxiang = [[UILabel alloc] initWithFrame:CGRectZero];
            fengxiang.tag = i + 400;
            fengxiang.textColor = [UIColor whiteColor];
            fengxiang.font = [UIFont systemFontOfSize:12];
            
            UILabel *fengli = [[UILabel alloc] initWithFrame:CGRectZero];
            fengli.tag = i + 500;
            fengli.textColor = [UIColor whiteColor];
            fengli.font = [UIFont systemFontOfSize:12];
            
            UILabel *date = [[UILabel alloc] initWithFrame:CGRectZero];
            date.tag = i + 600;
            date.textColor = [UIColor whiteColor];
            date.font = [UIFont systemFontOfSize:12];
            
            [self addSubview:hight];
            [self addSubview:low];
            [self addSubview:type];
            [self addSubview:date];
            [self addSubview:fengxiang];
            [self addSubview:fengli];
            [hight release];
            [low release];
            [type release];
            [date release];
            [fengli release];
            [fengxiang release];
            UIView *line = [[UIView alloc] init];
            line.backgroundColor = [UIColor grayColor];
            line.tag = i + 700;
            [self addSubview:line];
            [line release];
            
        }
        self.backgroundColor = [UIColor clearColor];
    }return self;
}
- (void)layoutSubviews {
    [super layoutSubviews];
    CGFloat tempWidth = [self getWidthWithText:self.tempe.text withFont:30];
    self.city.frame = CGRectMake((SCREEN_SIZE.width - 100) / 2, 20, 100, 50);
    self.tempe.frame = CGRectMake(20, SCREEN_SIZE.height / 2 - 150, tempWidth, 50);
    self.tempe2.frame = CGRectMake(tempWidth + 20, SCREEN_SIZE.height / 2 - 150, 200, 50);
    self.weathers.frame = CGRectMake(20, SCREEN_SIZE.height / 2 - 100, 100, 50);
    self.time.frame = CGRectMake(20, SCREEN_SIZE.height / 2 - 40, 100, 30);
    
    self.date.frame = CGRectMake(3, SCREEN_SIZE.height / 2, SCREEN_SIZE.width / 6, 30);
    self.type.frame = CGRectMake(3, SCREEN_SIZE.height / 2 + 40, SCREEN_SIZE.width / 6, 30);
    self.low.frame = CGRectMake(3, SCREEN_SIZE.height / 2 + 80, SCREEN_SIZE.width / 6, 30);
    self.hight.frame = CGRectMake(3, SCREEN_SIZE.height / 2 + 120, SCREEN_SIZE.width / 6, 30);
    self.fx.frame = CGRectMake(3, SCREEN_SIZE.height / 2 + 160, SCREEN_SIZE.width / 6, 30);
    self.fl.frame = CGRectMake(3, SCREEN_SIZE.height / 2 + 200, SCREEN_SIZE.width / 6, 30);
    for (int i = 0; i < 5; i++) {
        UILabel *hight = (UILabel *)[self viewWithTag:i + 100];
        UILabel *low = (UILabel *)[self viewWithTag:i + 200];
        UILabel *type = (UILabel *)[self viewWithTag:i + 300];
        UILabel *fengxiang = (UILabel *)[self viewWithTag:i + 400];
        UILabel *fengli = (UILabel *)[self viewWithTag:i + 500];
        UILabel *date = (UILabel *)[self viewWithTag:i + 600];
        UIView *line = (UIView *)[self viewWithTag:i + 700];
        line.frame = CGRectMake(SCREEN_SIZE.width / 6 * i + SCREEN_SIZE.width / 6, SCREEN_SIZE.height / 2, 1, 180);
        date.frame = CGRectMake(5 + SCREEN_SIZE.width / 6 * i + SCREEN_SIZE.width / 6, SCREEN_SIZE.height / 2, SCREEN_SIZE.width / 6, 30);
        type.frame = CGRectMake(5 + SCREEN_SIZE.width / 6 * i + SCREEN_SIZE.width / 6, SCREEN_SIZE.height / 2 + 40, SCREEN_SIZE.width / 6, 30);
        low.frame = CGRectMake(5 + SCREEN_SIZE.width / 6 * i + SCREEN_SIZE.width / 6, SCREEN_SIZE.height / 2 + 80, SCREEN_SIZE.width / 6, 30);
        hight.frame = CGRectMake(5 + SCREEN_SIZE.width / 6 * i + SCREEN_SIZE.width / 6, SCREEN_SIZE.height / 2 + 120, SCREEN_SIZE.width / 6, 30);
        fengxiang.frame = CGRectMake(5 + SCREEN_SIZE.width / 6 * i + SCREEN_SIZE.width / 6, SCREEN_SIZE.height / 2 + 160, SCREEN_SIZE.width / 6, 30);
        fengli.frame = CGRectMake(5 + SCREEN_SIZE.width / 6 * i + SCREEN_SIZE.width / 6, SCREEN_SIZE.height / 2 + 200, SCREEN_SIZE.width / 6, 30);
        
        
    }
    
    
}

- (void)setOneModel:(SAPWeatherOneModel *)oneModel {
    if (_oneModel != oneModel) {
        [_oneModel release];
        _oneModel = [oneModel retain];
    }
    
    
    self.city.text = oneModel.city;
    self.city.textAlignment = NSTextAlignmentCenter;
    self.city.font = [UIFont systemFontOfSize:30];
    self.city.textColor = [UIColor whiteColor];
    
    self.tempe.text = [NSString stringWithFormat:@"%@", oneModel.temp1];
    self.tempe.font = [UIFont systemFontOfSize:30];
    self.tempe.textColor = [UIColor whiteColor];
    
    self.tempe2.text = [NSString stringWithFormat:@"~~~%@", oneModel.temp2];
    self.tempe2.font = [UIFont systemFontOfSize:30];
    self.tempe2.textColor = [UIColor whiteColor];
    
    self.weathers.text = oneModel.weather;
    self.weathers.font = [UIFont systemFontOfSize:30];
    self.weathers.textColor = [UIColor whiteColor];
    
    self.time.text = [NSString stringWithFormat:@"%@更新", oneModel.ptime];
    self.time.backgroundColor = [UIColor orangeColor];
    self.time.alpha = 0.5;
    self.time.font = [UIFont systemFontOfSize:20];
    self.time.textColor = [UIColor whiteColor];
    
    
}
- (void)setTomorrowTowModel:(SAPTomorrowTwoModel *)tomorrowTowModel {
    if (_tomorrowTowModel != tomorrowTowModel) {
        [_tomorrowTowModel release];
        _tomorrowTowModel = [tomorrowTowModel retain];
    }
    self.hight.text = tomorrowTowModel.high;
    self.hight.font = [UIFont systemFontOfSize:12];
    self.hight.textColor = [UIColor whiteColor];

    self.low.text = tomorrowTowModel.low;
    self.low.textColor = [UIColor whiteColor];
    self.low.font = [UIFont systemFontOfSize:12];


    self.type.text = tomorrowTowModel.type;
    self.type.textColor = [UIColor whiteColor];
    self.type.font = [UIFont systemFontOfSize:12];

    self.fl.text = tomorrowTowModel.fl;
    self.fl.textColor = [UIColor whiteColor];
    self.fl.font = [UIFont systemFontOfSize:12];

    self.fx.text = tomorrowTowModel.fx;
    self.fx.textColor = [UIColor whiteColor];
    self.fx.font = [UIFont systemFontOfSize:12];

    self.date.text = tomorrowTowModel.date;
    self.date.textColor = [UIColor whiteColor];
    self.date.font = [UIFont systemFontOfSize:12];

}

- (void)setTomorrowOneModel:(SAPTomorrowOneModel *)tomorrowOneModel {
    if (_tomorrowOneModel != tomorrowOneModel) {
        [_tomorrowOneModel release];
        _tomorrowOneModel = [tomorrowOneModel retain];
        
        
    }
    
    
    for (int i = 0; i < 5; i++) {
        SAPTomorrowTwoModel *twoModel = tomorrowOneModel.forecastArr[i];
        UILabel *hight = (UILabel *)[self viewWithTag:i + 100];
        hight.text = twoModel.high;
        UILabel *low = (UILabel *)[self viewWithTag:i + 200];
        low.text = twoModel.low;
        UILabel *type = (UILabel *)[self viewWithTag:i + 300];
        type.text = twoModel.type;
        UILabel *fengxiang = (UILabel *)[self viewWithTag:i + 400];
        fengxiang.text = twoModel.fengxiang;
        UILabel *fengli = (UILabel *)[self viewWithTag:i + 500];
        fengli.text = twoModel.fengli;
        UILabel *date = (UILabel *)[self viewWithTag:i + 600];
        date.text = twoModel.date;
        UIView *line = (UIView *)[self viewWithTag:i + 700];
        
    }
}
- (CGFloat)getWidthWithText:(NSString *)text withFont:(CGFloat)font {
    NSDictionary *dic = @{NSFontAttributeName : [UIFont systemFontOfSize:font]};
    CGRect rect = [text boundingRectWithSize:CGSizeMake(CGFLOAT_MAX, 0) options:NSStringDrawingUsesLineFragmentOrigin attributes:dic context:nil];
    return rect.size.width;
}

- (CGFloat)getHeightWithText:(NSString *)text withFont:(CGFloat)font {
    NSDictionary *dic = @{NSFontAttributeName : [UIFont systemFontOfSize:font]};
    CGRect rect = [text boundingRectWithSize:CGSizeMake(0, CGFLOAT_MAX) options:NSStringDrawingUsesLineFragmentOrigin attributes:dic context:nil];
    return rect.size.height;
}

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
    
    // Configure the view for the selected state
}

@end
